             package com.java.diagnostics.visualizer.gc.realtimeV2.parser;
             
             import com.java.diagnostics.visualizer.parser.vgc.j9.J950DateConverter;
             import org.xml.sax.Attributes;
             
             public class TimeManager
             {
               double firstTimeStampMillis = -1.0D;
               CommonData commonData;
               boolean matchNominal = true;
               
               TimeManager(CommonData commonData) {
                 this.commonData = commonData;
               }
               
               private static double readTimeStamp(Attributes atts) {
                 String str = atts.getValue("timestamp");
                 if ((str != null) && (str.length() > 0)) {
                   double nominalTimeStamp = J950DateConverter.parseDate(str);
                   return nominalTimeStamp;
                 }
                 return -1.0D;
               }
               
               private void initializeFirstTimeStamp(double nominalTimeStamp)
               {
                 if (this.firstTimeStampMillis < 0.0D) {
                   this.firstTimeStampMillis = nominalTimeStamp;
                   
                   if (!this.commonData.hasInitialTime()) {
                     this.commonData.setInitialTime((long) (this.firstTimeStampMillis * 1000.0D));
                   }
                 }
               }
               
               long getTimeVal(Attributes atts) {
                 double nominalTimeStamp = readTimeStamp(atts);
                 initializeFirstTimeStamp(nominalTimeStamp);
                 long timeMicros;
                 //long timeMicros; 
                 if (this.commonData.hasInitialTime())
                 {
                   timeMicros = (long) (nominalTimeStamp * 1000L);
                 } else {
                   timeMicros = (long) ((nominalTimeStamp - this.firstTimeStampMillis) * 1000.0D);
                 }
                 return timeMicros;
               }
               
               long getTimeVal(Attributes atts, long timeMicros)
               {
                 double nominalTimeStamp = readTimeStamp(atts);
                 return getTimeVal(nominalTimeStamp, timeMicros);
               }
               
               long getTimeVal(double nominalTimeStamp, long timeMicros)
               {
                 initializeFirstTimeStamp(nominalTimeStamp);
                 if (timeMicros < this.commonData.getInitialTimeMicros()) {
                   timeMicros = this.commonData.getInitialTimeMicros();
                 }
                 
                 double elapsedMicros = timeMicros - this.commonData.getInitialTimeMicros();
                 double maxElapsedByTimeStampMillis = nominalTimeStamp - this.firstTimeStampMillis + 1000.0D;
                 if (maxElapsedByTimeStampMillis * 1000.0D < elapsedMicros) {
                   timeMicros = (long) (this.commonData.getInitialTimeMicros() + maxElapsedByTimeStampMillis * 1000.0D);
                 }
                 
                 double minElapsedByTimeStampMillis = nominalTimeStamp - this.firstTimeStampMillis - 1000.0D;
                 if (minElapsedByTimeStampMillis * 1000.0D > elapsedMicros) {
                   timeMicros = (long) (this.commonData.getInitialTimeMicros() + minElapsedByTimeStampMillis * 1000.0D);
                 }
                 
                 if ((this.matchNominal) && (this.commonData.hasInitialTime()) && 
                   (timeMicros / 1000.0D < nominalTimeStamp)) {
                   timeMicros = (long) (nominalTimeStamp * 1000L);
                 }
                 return timeMicros;
               }
             }


